﻿using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Inlycat;

public class test : MonoBehaviour
{
    FileDownloader fd = new FileDownloader(true);
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnGUI()
    {
        if (GUI.Button(new Rect(10,10,100,50),"Click"))
        {
            CoroutineManager.Instance.DoActionWithDelay(new List<Action>()
            {
                ()=>{TimeFlagManager.Instance.SetTimeFlag("test","coroutine",FlagState.Start);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{Debug.Log(Time.time);},
                ()=>{TimeFlagManager.Instance.SetTimeFlag("test","coroutine",FlagState.Finish);},
                TimeFlagManager.Instance.LogData
            },1f);

            fd.Files = new List<FileDownloader.FileInfo>()
            {
                new FileDownloader.FileInfo("http://imgsrc.baidu.com/forum/w%3D580/sign=798a006e54fbb2fb342b581a7f4a2043/549cfaf2b2119313901af78364380cd790238d82.jpg"),
                new FileDownloader.FileInfo("http://dl.cgz-invest.com/cyzm/vs")
            };
            fd.FileDownloadSucceeded += fd_FileDownloadSucceeded;
            fd.StateChanged += fd_FileDownloadSucceeded;
            fd.LocalDirectory = "C:/";
            fd.Start();
        }
    }

    void fd_FileDownloadSucceeded(object sender, EventArgs e)
    {
        Debug.Log(sender.ToString());
        Debug.Log(e.ToString());
        Debug.Log(fd.TotalPercentage());
        Debug.Log(fd.TotalProgress);
        Debug.Log(fd.TotalSize);
    }
}
